package com.rfid.project.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rfid.project.model.People;
import com.rfid.project.model.Position;
import com.rfid.project.model.ProjectMilestoneChange;
import com.rfid.project.model.ProjectStakeholderType;

@Service
@Transactional
public class ProcessSourceForProjectMilestoneChange {
	@Autowired
	private ProjectMilestoneChangeService projectMilestoneChangeService;

	@Autowired
	private PeopleService peopleService;

	public List<Process> getCurrentTaskListByProcessor(People people) {
		List<Process> resultList = new ArrayList<Process>();
		List<ProjectMilestoneChange> projectMilestoneChanges = null;
		if (people.getPosition().getId().equals(Position.PLAN_ID)) {
			// 如果当前用户为计划调度岗，则查询所有状态为提交的项目节点延期申请
			projectMilestoneChanges = projectMilestoneChangeService.findByStatus(people, ProjectStakeholderType.DEPT_PLAN, ProcessStatus.DELAY_APPLY);
		}
		if (projectMilestoneChanges != null) {
			for (ProjectMilestoneChange projectMilestoneChange : projectMilestoneChanges) {
				Process processTask = new Process();
				processTask.setBizId(projectMilestoneChange.getId());
				processTask.setSubmitPerson(projectMilestoneChange.getApplyPerson());
				processTask.setSubmitTime(projectMilestoneChange.getApplyTime());
				processTask.setProcessStatusId(projectMilestoneChange.getStatus());
				processTask.setProcessTypeId(ProcessType.PROJECT_MILESTONE_DELAY);
				processTask.setProcessTitle(projectMilestoneChange.getProjectMilestone().getProject().getName() +"_"+ projectMilestoneChange.getProjectMilestone().getName() + "_申请延期!");
				resultList.add(processTask);
			}
		}
		return resultList;
	}

	public List<Process> getCurrentTaskListByCreator(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Process> getHistoryTaskListByProcessor(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<Process> getHistoryTaskListByCreator(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}
}
